package org.ws.edu.task1;

import java.util.Arrays;
import java.util.Collection;

import junit.framework.Assert;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.ws.edu.task1.ikhmyz.ConsoleHandlerKHMZ;
import org.ws.edu.task1.jimotozka.JimotozkaConsoleHandler;
import org.ws.edu.task1.oksana.ConsoleHandlerOk;
import org.ws.edu.task1.pool.CalcNumMain;
import org.ws.edu.task1.qizer.ConsoleHandlerQ;
import org.ws.edu.task1.storolfr.ConsoleHandlerS;

/**
 * @author sergey.valuy
 */
@RunWith(Parameterized.class)
public class ConsoleHandlerTest
{
    private final IConsoleHandler handler;

    public ConsoleHandlerTest(IConsoleHandler handler)
    {
        this.handler = handler;
    }

    @Parameters
    public static Collection<Object[]> data()
    {
        Object[][] data = new Object[][] { {new CalcNumMain(),}, {new JimotozkaConsoleHandler()}, {new ConsoleHandlerQ()},
            {new ConsoleHandlerOk()}, {new ConsoleHandlerS()}, {new ConsoleHandlerKHMZ()}};
        // TODO: add your handler here
        return Arrays.asList(data);
    }

    protected static String[] incorrect_expression = {"", "iufvhbvbknvzxkja", "x+y", "+", "5/0"};

    protected static String[][] simple_expression = { {"2+2", "4.0"}, {"2-12", "-10.0"}, {"2*12", "24.0"}, {"10/5", "2.0"}};

    protected static String[][] complex_expression = {{"((2+3*2)+((2/4+5)- 2)*3 )*2", "37.0"}};

    protected static String[][] extra_expression = {{"(8-5)!", "6.0"}};

    /**
     * Test method for
     * {@link org.ws.edu.task1.IConsoleHandler#handle(java.lang.String)}.
     */
    @Test
    public void testIncorrectInput()
    {
        for (String expression : incorrect_expression)
        {
            String result = handler.handle(expression);
            Assert.assertNotNull(result);
            System.out.println(result);
        }
    }

    /**
     * Test method for
     * {@link org.ws.edu.task1.IConsoleHandler#handle(java.lang.String)}.
     */
    @Test
    public void testSimple()
    {
        for (String[] exp : simple_expression)
        {
            String msg = exp[0];
            Assert.assertEquals(msg, exp[1], handler.handle(exp[0]));
            System.out.println(msg + exp[1] + " is ok");
        }
    }

    /**
     * Test method for
     * {@link org.ws.edu.task1.IConsoleHandler#handle(java.lang.String)}.
     */
    @Test
    public void testComplex()
    {
        for (String[] exp : complex_expression)
        {
            String msg = exp[0];
            Assert.assertEquals(msg, exp[1], handler.handle(exp[0]));
            System.out.println(msg + exp[1] + " is ok");
        }
    }

    /**
     * Test method for
     * {@link org.ws.edu.task1.IConsoleHandler#handle(java.lang.String)}.
     */
    @Test
    public void testExtra()
    {
        for (String[] exp : extra_expression)
        {
            String msg = exp[0];
            Assert.assertEquals(msg, exp[1], handler.handle(exp[0]));
            System.out.println(msg + exp[1] + " is ok");
        }
    }
}
